package com.bianmaba.remote.supports;

import com.bianmaba.commons.bean.result.OperationResult;
import lombok.extern.log4j.Log4j2;
import org.springframework.http.HttpEntity;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
@Log4j2
public class MetricRemoteRequestService extends BaseRemoteRequestService implements IBaseRemoteRequestService {
    public OperationResult postForMap(String url, HttpEntity entity) {
        try {
            ResponseEntity<Map> response = postForEntity(url, entity, Map.class);
            Map<String, Object> body = response.getBody();
            return OperationResult.of(true).setData(body);
        } catch (Exception e) {
            return handleException(url, entity.getBody().toString(), e);
        }
    }

    public OperationResult postForList(String url, HttpEntity entity) {
        try {
            ResponseEntity<List> response = postForEntity(url, entity, List.class);
            List<Map<String, Object>> body = response.getBody();
            return OperationResult.of(true).setData(body);
        } catch (Exception e) {
            return handleException(url, entity.getBody().toString(), e);
        }
    }
}
